import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { SharedModule } from '../../../shared/shared.module';
import { Store } from '@ngxs/store';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { UserSelector } from '../store/user.selector';

@Component({
  selector: 'app-user-edit-form',
  standalone: true,
  imports: [CommonModule, SharedModule],
  templateUrl: './user-edit-form.component.html',
  styleUrl: './user-edit-form.component.scss',
})
export class UserEditFormComponent {
  validateForm: FormGroup;


  constructor(private fb: FormBuilder, private store: Store, private ref: NzModalRef) {
    this.validateForm = this.fb.group({
      id: [''],
      email: ['', [Validators.email, Validators.required]],
      nickname: [''],
    });
    this.store.select(UserSelector.editFormFlag).subscribe(r => {
      if (!r) this.ref.destroy();
    });
  }
}
